package org.example.product.Controller;

import org.example.product.Entity.Product;
import org.example.product.Service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin("*")
@RestController
public class ProductController {

    @Autowired
    private ProductService productService;

    @GetMapping("/search")
    public List<Product> search(@RequestParam(required = false) String category, @RequestParam(required = false) String keyword) {
        return productService.searchProducts(category, keyword);
    }
}